package com.t21;

import java.util.Random;

/**
 * Created by xuyiwei on 2018/9/23.
 */
public class ThreadLocalDemo {
    public static void main(String[] args) {
        ThreadLocal<Integer> value = new ThreadLocal<Integer>(){
            private Random rand = new Random(47);
            protected synchronized Integer initialValue() {
                System.out.println("产生一个随机值");
                return rand.nextInt(10000);
            }
        };
        value.set(value.get());
        System.out.println(value.get());
        System.out.println(value.get());
    }
}
